home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / xrf.arc / XRFR.C < prev   
Encoding:
C/C++ Source or Header  |  1986-04-20  |  7.6 KB  |  223 lines

  1. /*
  2.  *                      ***************
  3.  *                      * X R F R . C *
  4.  *                      ***************
  5.  *
  6.  * Do initialization things & special Rainbow code (was XRFI.C).
  7.  *
  8.  * Version V1.4                  1-Jul-80
  9.  * Version V1.5                  3-Jul-80  Conditionaled date/time stuff.
  10.  * Version V1.6 MM         9-Jul-80  Changed date/time stuff
  11.  * Version V1.7 MM        10-Jul-80  File name changes
  12.  * Version V1.8 MM        21-Jul-80  Ctime() changed
  13.  * Version V1.9 MM        22-Jul-80  Redid initialization
  14.  * Version V1.11 RBD        26-Dec-80  Cleanup rt11 usage message
  15.  * Version V1.12 MM        22-Dec-81  Rtime isn't in vax library
  16.  * Version V1.13 MM        16-Feb-82  ctime fixup
  17.  * Version V1.14 MC        29-Dec-84  tailor for DEC Rainbow
  18.  *                               4-Jan-84  add spooler to PRINT Queue if
  19.  *                                         installed.
  20.  *                 8-Jan-85  Add date/time plus return name
  21.  * Version V1.16 MC        29-Mar-85  Add -f support to help
  22.  * version V1.18 MC        16-Apr-85  Add pathing
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include "xrf.h"
  27.  
  28. /*****************************************************************/
  29. /*                  RAINBOW/MSDOS TAILORING                      */
  30. /*****************************************************************/
  31. static char ff_omode[2] = " ";
  32. static int  ff_search_code = 0x4e00;
  33. static unsigned char ff_fb[65] = "";    /*search filespec*/
  34. static unsigned char ff_fc[65] = "";    /*current filespec*/
  35. static unsigned char ffcp[65] = "";    /*search path*/
  36. static unsigned char ff_fw[65] = "";    /*def work file name*/
  37. static unsigned char ff_fa[65] = "";    /*act work file name*/
  38. static struct ff_str { 
  39.   char dummy[21];        /* reserved for dos */ 
  40.   unsigned char attribute;    /* returned attribute */ 
  41.   unsigned time; 
  42.   unsigned date; 
  43.   long size;            /* size of file */ 
  44.   unsigned char fn[13];        /* string containing the filename */ 
  45. } ff_area; 
  46.  
  47.  
  48. /*****************************************************************/
  49. /*        Give user help on program useage.                      */
  50. /*****************************************************************/
  51.  
  52. useage()
  53.    {
  54.    printf("Usage: xrf [-options] [-o outfile] infile[s]\n\n");
  55.    printf("       -s  Spool output file to PRINT queue\n");
  56.    printf("       -n  Narrow (80 column) output else wide (132)\n");
  57.    printf("       -i  Expanded Symbols (31), else 8 chars.\n");
  58.    printf("       -f  Process functions only, else do all symbols.\n");
  59.    printf("       -p  Print C source (with linenumbers) as well.\n");
  60.    printf("       -c  Concatanate input files(s)\n");
  61.    printf("       -v  verbose mode\n");
  62.    printf("       -o  Output to \"outfile\" (next param)\n\n");
  63.    printf("Input file(s) may have wild-card names [the");
  64.    printf(" filetype of \".c\" is added by XRF].\n");
  65.    printf("The default output filename is \"<first_input_file>.REF\"\n\n");
  66.    printf("E.G. XRF -NIC -O XRF XRF* SPOOL will do a combined\n");
  67.    printf("     crossreference of XRF?????.C and SPOOL.C as XRF.REF\n\n");
  68.    abort("See XRF.DOC for more information.");
  69.    }
  70.  
  71.  
  72. /*****************************************************************/
  73. /*       Initialise input file system                            */
  74. /*****************************************************************/
  75.  
  76. initinfile(in)
  77. char *in;
  78.  
  79. { FILE *ffirst();
  80.   int i;
  81.   unsigned char *cs=ff_area.fn, *cd=ff_fw, *concat();
  82.   if(src!=NULL){fclose(src); src=NULL;}
  83.     gpath(in);
  84.     if((src = ffirst(concat(ff_fb,in,".c",0), "r")) == ULL)
  85.        abort("Cannot open %s\n", ff_fb);
  86.     for(;*cs!='.';*cd++=*cs++);            /*save name for output*/
  87.     *cd='\0';
  88. }
  89.  
  90. /*****************************************************************/
  91. /*       Initialise output file system                           */
  92. /*****************************************************************/
  93.  
  94. initoutfile(out)
  95. char    *out;
  96.    {
  97.    unsigned char *concat();
  98.    FILE *fopen();
  99.    if (out == NULL)out=ff_fw;
  100.    if((lst = fopen(concat(ff_fa,out,".ref",0), "w")) == NULL)
  101.       abort("Cannot open output reference file %s\n", ff_fa);
  102.    }
  103.  
  104. /*****************************************************************/
  105. /*       set next input file to be processed                     */
  106. /* open file & initialize page header strings                    */
  107. /*****************************************************************/
  108.  
  109.  
  110. nextinfile()
  111. {
  112.    FILE     *ffnext();
  113.    unsigned char *cp=ff_area.fn,*concat();
  114.    unsigned char datetemp[23], timetemp[9];
  115.    int i;
  116.    if ((src=ffnext(src)) == NULL)
  117.       return(0);
  118.    for(i=0;*cp!='.'&&i<8;progname[i++]=*cp++); /* set curr name */
  119.    while(i<8)progname[i++]=' ';
  120.    progname[i]='\0';
  121.    if(verbose)printf("Processing %s ...\n",ff_fc);
  122.    concat(pghead, "\fXRF Source Listing of: ",
  123.          ff_area.fn,"\t",thedate," ",thetime,"\tPage ", 0);
  124.  
  125.    ff_search_code=0x4f00;            /*search next*/
  126.    return(1);
  127. }
  128.  
  129. /*****************************************************************/
  130. /*          RAINBOW/MSDOS support routines                       */
  131. /*****************************************************************/
  132.  
  133. static FILE *ffirst(filename,mode)
  134. unsigned char *filename;
  135. unsigned char *mode;
  136. { struct {int ax,bx,cx,dx,si,di,ds,es;}srv;
  137.   FILE *fopen();
  138.   unsigned char *concat();
  139.     segread(&srv.si);            /* get ds value */
  140.     srv.ax=ff_search_code=0x4e00;        /* search first*/
  141.     srv.cx=0;                /* set search modes */
  142.     srv.dx=filename;
  143.     bdos(0x1a,&ff_area);            /* set the transfer address */
  144.     strcpy(ff_omode,mode);
  145.     if(!(sysin21(&srv,&srv)&1))
  146.     return fopen(concat(ff_fc,ff_cp,ff_area.fn,0),mode);
  147.     return NULL;
  148.  
  149. static FILE *ffnext(iop)
  150. FILE *iop;
  151. { int i;
  152.   struct {int ax,bx,cx,dx,si,di,ds,es;}srv;
  153.   FILE *freopen();
  154.   unsigned char *concat();
  155.     segread(&srv.si);        /* get ds value */
  156.     srv.ax=ff_search_code;
  157.     srv.cx=0;            /* set search modes */
  158.     srv.dx=ff_fb;
  159.     bdos(0x1a,&ff_area);        /* set the transfer address */
  160.     if(!(sysint21(&srv,&srv)&1))
  161.     return freopen(concat(ff_fc,ff_cp,ff_area.fn,0),ff_omode,iop);
  162.   return NULL;
  163.  
  164. fspool(iop)            /*trigger off spool print of output file*/
  165. FILE *iop;
  166. { fclose(iop);                /*ensure file shut */
  167.   if(spool(ff_fa))printf("ERR - Can't spool print %s\n",ff_fa);
  168.    else printf("%s queued for printing...\n",ff_fa);
  169. }
  170.  
  171. delete(filename)
  172. char *filename;
  173. { return unlink(filename);}
  174.  
  175. /* get system date & time */
  176. static char *dayofweek[] = { "Sunday","Monday","Tuesday","Wednesday",
  177.                             "Thursday","Friday","Saturday" };
  178. static char *monthname[] = { "Jan","Feb","Mar","Apr","May","Jun","Jul",
  179.                             "Aug","Sep","Oct","Nov","Dec" };
  180. date(d)            /* return date into d[23] */
  181. char *d;
  182. { struct {int ax,bx,cx,dx,si,di,ds,es;}srv;
  183.   srv.ax=0x2A00;
  184.   sysint21(&srv,&srv);
  185.   sprintf(d,"%s, %2d %s %04d",dayofweek[srv.ax&0xFF],srv.dx&0xFF,
  186.                               monthname[srv.dx>>8],srv.cx);
  187. }
  188.  
  189. time(t)                /* return time into t[9] */
  190. char *t;
  191. { struct {int ax,bx,cx,dx,si,di,ds,es;}srv;
  192.   srv.ax=0x2C00;
  193.   sysint21(&srv,&srv);
  194.   sprintf(t,"%02d:%02d:%02d",srv.cx>>8,srv.cx&0xFF,srv.dx>>8);
  195. }
  196.  
  197. /* concatanate 'n' strings to new output string*/
  198. /* concat(out,ip1,ip2...ipn,0); !last parameter MUST be 0! */
  199. /* returns pointer to output string*/
  200.  
  201. unsigned char *concat(op,ip)
  202. unsigned char *op;
  203. int *ip;
  204. { unsigned char *r=op,*cp,**cpp=&ip;
  205.  
  206.   *op='\0';
  207.   while(*cpp){
  208.     strcat(op,(cp=*cpp++));
  209.     op+=strlen(cp);
  210.     }
  211.   return r;
  212. }
  213.  
  214. static gpath(fn)    /*extract path (if present) from filestring */
  215. cha *fn;
  216. { int i, j;
  217.     for(j=strlen(fn);j;j--)if(fn[j-1]=='\\')break;
  218.     for(i=0;i<j;ff_cp[i++]=toupper(*fn++));
  219.     ff_cp[i++]='\0';
  220. }
  221.